let context = null
const initContext = (vue) => {
	context = vue;
}
//产品搜索
const productListAsync = async (UserPhone, ProductKeyword, PageIndex, PageSize, token) => {

	let IdentifyId = "ProductList";
	var objects = {
		'ProductKeyword': ProductKeyword,
		'PageIndex': PageIndex,
		'UserId': UserPhone,
		'PageSize': PageSize
	};
	let strObject = JSON.stringify(objects);
	
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		//console.log(result);

		return result.data;
	}
	return null;
}

//配件搜索
const AccessoriesFindAsync = async (UserId, ProductKeyword, PartsKeyword, 
PageIndex, PageSize, OnlyRO, token) => {
	let IdentifyId = "PartsList";
	var objects = {
		'UserId': UserId,
		'ProductKeyword': ProductKeyword,
		'PartsKeyword': PartsKeyword,
		'PageIndex': PageIndex,
		'PageSize': PageSize,
		'OnlyRO': OnlyRO,
	};
	let strObject = JSON.stringify(objects);
	let [error, result] = await context.commService.postEntityAsync(IdentifyId, strObject, token);
	if (!error && result.statusCode == 200) {
		console.log(result);
		return result.data;
	}
	return null;
}

const productlistservice = {
	initContext,
	productListAsync,
	AccessoriesFindAsync,
}

export default productlistservice
